//
//  HBaseConfig.m
//  SSIL
//
//  Created by 余胜民 on 16/5/13.
//  Copyright © 2016年 sanmy. All rights reserved.
//

#import "HBaseConfig.h"

@implementation HBaseConfig
+ (void)setTheme{
    
    /**
     *  设置默认导航
     */
    [self setNavigationBar];
    
    
    /**
     *  设置默认状态条
     */
    [self setStatusBar];
    
    /**
     *  设置推送
     */
    [self setPush];
    
    /**
     *  设置主界面
     */
   // [self setMainViewController];
    
    /**
     *   设置是否第一次启动
     */
    [self setFirst];
}
/**
 *  设置默认状态条
 */
+ (void)setStatusBar{
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}

/**
 *  设置默认导航
 */
+ (void)setNavigationBar{
    if (IsIOS7) {
        [[UINavigationBar appearance] setBarTintColor:[UIColor baseNaviBackGroundColor]];
    }
    [[UINavigationBar appearance] setTintColor:[UIColor baseNaviLeftAndRightTextColor]];
    //字体白颜色
    [[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor baseNaviTitleTextColor],NSFontAttributeName:[UIFont bigFont]}];
    
    /**
     *  导航颜色
     */
    [[UINavigationBar appearance] setBackgroundImage:[UIImage imageWithColor:[UIColor baseNaviBackGroundColor]] forBarMetrics:UIBarMetricsDefault];
    
    /**
     *  导航阴影线
     */
    [[UINavigationBar appearance] setShadowImage:[[UIImage imageWithColor:[UIColor colorFromHexRGB:@"b1b1b1"]] scaleToSize:CGSizeMake(SCREEN_WIDTH, 0.4)]];
}

/**
 *  设置推送
 */

+ (void)setPush{
    if (IsIOS8) {
        UIUserNotificationType myTypes = UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound;
        UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:myTypes categories:nil];
        [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
    }else{
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert)];
    }
}

/**
 *  设置主界面
 */

+ (void)setMainViewController{
    UIWindow * rootWindow = [UIApplication sharedApplication].windows[0];
    UITabBarController *tabBarController = (UITabBarController *)rootWindow.rootViewController;
    UITabBar *tabBar                     = tabBarController.tabBar;
    
    tabBar.shadowImage = [[UIImage imageWithColor:[UIColor colorFromHexRGB:@"b1b1b1"]] scaleToSize:CGSizeMake(SCREEN_WIDTH, 0.4)];
    tabBar.backgroundImage = [UIImage imageWithColor:[UIColor colorFromHexRGB:@"fafafa"]];
    tabBar.translucent = NO;
    
    
    UITabBarItem* item1                  = [tabBar.items objectAtIndex:0];
    [item1 setImage:[[UIImage imageNamed:@"tab_recommend_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item1 setSelectedImage:[[UIImage imageNamed:@"tab_recommend_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item1 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIColor colorFromHexRGB:@"7A7E83"], NSForegroundColorAttributeName,
                                   nil] forState:UIControlStateNormal];
    [item1 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIColor colorFromHexRGB:@"FF6c00"], NSForegroundColorAttributeName,
                                   nil] forState:UIControlStateSelected];
    
    UITabBarItem* item2                  = [tabBar.items objectAtIndex:1];
    [item2 setImage:[[UIImage imageNamed:@"tab_checkdata_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item2 setSelectedImage:[[UIImage imageNamed:@"tab_checkdata_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item2 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIColor colorFromHexRGB:@"7A7E83"], NSForegroundColorAttributeName,
                                   nil] forState:UIControlStateNormal];
    [item2 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIColor colorFromHexRGB:@"FF6c00"], NSForegroundColorAttributeName,
                                   nil] forState:UIControlStateSelected];
    
    UITabBarItem* item3                  = [tabBar.items objectAtIndex:2];
    [item3 setImage:[[UIImage imageNamed:@"tab_consultation_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item3 setSelectedImage:[[UIImage imageNamed:@"tab_consultation_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item3 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIColor colorFromHexRGB:@"7A7E83"], NSForegroundColorAttributeName,
                                   nil] forState:UIControlStateNormal];
    [item3 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIColor colorFromHexRGB:@"FF6c00"], NSForegroundColorAttributeName,
                                   nil] forState:UIControlStateSelected];
    
    UITabBarItem* item4                  = [tabBar.items objectAtIndex:3];
    [item4 setImage:[[UIImage imageNamed:@"tab_my_normal"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item4 setSelectedImage:[[UIImage imageNamed:@"tab_my_selected"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    [item4 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIColor colorFromHexRGB:@"7A7E83"], NSForegroundColorAttributeName,
                                   nil] forState:UIControlStateNormal];
    [item4 setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                   [UIColor colorFromHexRGB:@"FF6c00"], NSForegroundColorAttributeName,
                                   nil] forState:UIControlStateSelected];
}

/**
 *   设置是否第一次启动
 */
+ (void)setFirst{
    if (![[NSUserDefaults standardUserDefaults] boolForKey:@"everLaunched"])
    {
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"everLaunched"];
        [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"firstLaunch"];
        /**
         *  设置设备ID
         */
       // [self setDeviceID];
    }
    else
    {
        [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"firstLaunch"];
    }
}

/**
 *   是否是第一次安装
 */

+ (BOOL)isFirstLaunch{
    return [[NSUserDefaults standardUserDefaults] boolForKey:@"firstLaunch"];
}

///**
// *  设置设备ID
// */
//
//+ (void)setDeviceID{
//    NSString *deviceID = [DeviceID deviceID];
//    [[NSUserDefaults standardUserDefaults] setObject:deviceID forKey:@"deviceID"];
//}

/**
 *  是否是VIP版本
 */
+ (BOOL)isVip{
    NSDictionary * dic  = [[NSBundle mainBundle] infoDictionary];
    NSString * bundleId = [dic objectForKey:@"CFBundleIdentifier"];
    return ![bundleId isEqualToString:@"com.lexue.lexuezhiyuan"];
}

@end
